<?php 
class TagController extends CommonController{
	public function index(){

			$model=M('Tag');
			$TagData=$model->all();
			// p($TagData);
			$this->assign('TagData',$TagData);
			$this->display();
	
	}

	//添加方法
	public function add(){
		if(IS_POST){
			$model=M('Tag');
			$re=$model->add($_POST);
			if($re){
				$this->success('添加成功','Tag/index');
			}else{
				$this->success('添加失败','Tag/index');
			}
		}else{
			$this->display();
		}
	}

	//修改方法
	public function edit(){
		$tag=M('Tag');
		if(IS_POST){
			p($_POST);die;
			$tid=$_POST['tid'];
			$re=$tag->where(array('tid'=>$tid))->save();
				if($re){
					$this->success('修改成功',U('Tag/index'));
				}else{
					$this->error('修改失败',U('Tag/index'));
				}
		}else{
			$tid=intval($_GET['tid']);
			$tagData_all=$tag->all();//查询所有
			$this->assign('tagData_all',$tagData_all);
			$tagData=$tag->where(array('tid'=>$tid))->all();
			// p($tagData);
			$this->assign('tagData',$tagData);
			$this->display();
		}
	}

//删除
	public function del(){
		$tid=intval($_GET['tid']);
		$tag=M('Tag');
		$re=$tag->where(array('tid'=>$tid))->del();
		if($re){
			$this->success('删除成功',U('Tag/index'));
		}else{
			$this->error('删除失败',U('Tag/index'));
		}
	}
}


 ?>